//===============================================================================
// Microsoft Architecture Strategy Team
// LitwareHR - SaaS Sample Application
//===============================================================================
// Copyright  Microsoft Corporation.  All rights reserved.
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE.
//===============================================================================
// The example companies, organizations, products, domain names,
// e-mail addresses, logos, people, places, and events depicted
// herein are fictitious.  No association with any real company,
// organization, product, domain name, email address, logo, person,
// places, or events is intended or should be inferred.
//===============================================================================


//===============================================================================
// Microsoft Architecture Strategy Team
// LitwareHR - S+S Sample Application
//===============================================================================
// Copyright  Microsoft Corporation.  All rights reserved.
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE.
//===============================================================================
// The example companies, organizations, products, domain names,
// e-mail addresses, logos, people, places, and events depicted
// herein are fictitious.  No association with any real company,
// organization, product, domain name, email address, logo, person,
// places, or events is intended or should be inferred.
//===============================================================================

using System;
using System.Collections.Generic;
using System.Text;
using LitwareHR.PublicApp.WinUX.ServiceProxy;
using Shp.Runtime.Contract;
using LitwareHR.Recruiting.Contract;
using Microsoft.Practices.ObjectBuilder;
using Microsoft.Practices.CompositeUI;
using LitwareHR.PublicApp.WinUX.ServiceProxy.UnSecure;
using System.Collections.ObjectModel;
     
namespace LitwareHR.PublicApp.WinUX.Services
{
    public class ProcessService
    {
        private DataModelService _dataModelService = null;

        [InjectionConstructor]
        public ProcessService( [ServiceDependency] DataModelService dataModelService )
        {
            this._dataModelService = dataModelService;
        }

        public Collection<Guid> GetOpenPositionList(Guid tenantId)
        {
           using (ServiceProxy.UnSecure.ProcessService  channel = new ServiceProxy.UnSecure.ProcessService())
           {
               return channel.GetOpenPositionList(tenantId);
           }
        }

        public StringPair[][] GetOpenPositions( TenantInfo tenant )
        {
            StringPair[][] instanceList = null;

            //Get the List of Open positions (just returns the Guids in the current implementation)
            Collection<Guid> positions = GetOpenPositionList( tenant.Id );

            if( positions.Count > 0 )
            {
                List<Guid> positionsGuids = new List<Guid>(positions);
                instanceList = _dataModelService.GetInstanceList(tenant.Alias, Constants.Entity.Position, positionsGuids.ToArray());
            }
            return instanceList;
        }

        public StringPair[][] GetOpenPositions(TenantInfo tenant, Collection<Guid> positions)
        {
            StringPair[][] instanceList = null;
                        
            if (positions.Count > 0)
            {
                List<Guid> positionsGuids = new List<Guid>(positions);
                instanceList = _dataModelService.GetInstanceList(tenant.Alias, Constants.Entity.Position, positionsGuids.ToArray());
            }
            
            return instanceList;
        }

        public Guid OpenRecruitingProcess(LitwareHR.Recruiting.Contract.Position position)
        {
            using (ServiceProxy.Secure.ProcessService channel = new ServiceProxy.Secure.ProcessService())
            {
                return channel.OpenRecruitingProcess(position);
            }
        }

        public StringPair[][] GetRecruitingWorkflowListByApplicant(bool isOpen)
        {
            using (ServiceProxy.Secure.ProcessService channel = new ServiceProxy.Secure.ProcessService())
            {
                return channel.GetRecruitingWorkflowListByApplicant(isOpen);
            }
        }

         public StringPair[][] GetRecruitingWorkflowList(bool isOpen)
        {
            using (ServiceProxy.Secure.ProcessService channel = new ServiceProxy.Secure.ProcessService())
            {
                return channel.GetRecruitingWorkflowList(isOpen);
            }
        }

         public void SubmitResume(Resume resume)
        {
            using (ServiceProxy.Secure.ProcessService channel = new ServiceProxy.Secure.ProcessService())
            {
                channel.SubmitResume(resume);
            }
        }

         public void SubmitInterview(Interview interview)
        {
            using (ServiceProxy.Secure.ProcessService channel = new ServiceProxy.Secure.ProcessService())
            {
                channel.SubmitInterview(interview);
            }
        }

         public void SubmitNegotiation(Negotiation negotiation)
        {
            using (ServiceProxy.Secure.ProcessService channel = new ServiceProxy.Secure.ProcessService())
            {
                channel.SubmitNegotiation(negotiation);
            }
        }

         public void SubmitAcceptance(Acceptance acceptance)
        {
            using (ServiceProxy.Secure.ProcessService channel = new ServiceProxy.Secure.ProcessService())
            {
                channel.SubmitAcceptance(acceptance);
            }
        }

         public void SubmitRejection(Rejection rejection)
        {
            using (ServiceProxy.Secure.ProcessService channel = new ServiceProxy.Secure.ProcessService())
            {
                channel.SubmitRejection(rejection);
            }
        }

        public Collection<Position> GetOpenPositionEntityList()
        {
            using (ServiceProxy.Secure.ProcessService channel = new ServiceProxy.Secure.ProcessService())
            {
                return channel.GetOpenPositionEntityList();
            }
        }


        internal Resume GetResume(Guid resumeId)
        {
            using (ServiceProxy.Secure.ProcessService channel = new ServiceProxy.Secure.ProcessService())
            {
                return channel.GetResume(resumeId);
            }
        }

        internal SilverlightAccount GetSilverligtAccount()
        {
            using (ServiceProxy.Secure.ProcessService channel = new ServiceProxy.Secure.ProcessService())
            {
                return channel.GetSilverlightAccount();
            }
        }
    }
}
